package com.spsy;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
@EnableAsync
public class xiancheng {

    @Bean("xianchengzu1")
    public Executor createxiancheng(){
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        threadPoolTaskExecutor.setCorePoolSize(5); //核心线程数
        threadPoolTaskExecutor.setMaxPoolSize(10); //最大线程数
        threadPoolTaskExecutor.setQueueCapacity(100); //队列容量
        threadPoolTaskExecutor.setKeepAliveSeconds(60); //空闲线程存活时间
        threadPoolTaskExecutor.setThreadNamePrefix("Async-"); //线程名前缀

        //拒绝策略
        threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        threadPoolTaskExecutor.initialize(); //线程组初始化
        return threadPoolTaskExecutor;
    }
}
